<?php

$key = '!*rxCnSu34SIOyj&KlchEhVF%ni5PjTS';
//gid=524288&uid=360257&sign=A220346FF5D3BCCAD351914B39B9590E
$params = ['gid' => '524288', 'uid' => '360684'];
// $params['type'] = '0';
// $params['category'] = '15';
$params['id'] = '68';
// $params['mobile'] = '13410896027';

$params['sign'] = makeSignNew($params, $key);

echo toUrl($params);

function toUrl($params)
{
    $string = '';
    foreach ($params as $k => $v) {
        $string .= $k . "=" . $v . "&";
    }
    $string = rtrim($string, '&');
    return $string;
}

function makeSignNew($params, $key)
{
    //转换成字符串
    array_map(function (&$val) {
        $val = strval($val);
    }, $params);
    $params = array_filter($params, function ($value) {
        return $value != '';
    });
    //签名步骤一：按字典序排序参数
    ksort($params, SORT_STRING);
    //签名步骤二：在string后加入KEY
    $params['key'] = $key;
    //$string = http_build_query($params);
    $string = '';
    foreach ($params as $k => $v) {
        $string .= $k . "=" . $v . "&";
    }
    $string = rtrim($string, '&');
    //签名步骤三：MD5加密
    $string = md5($string);
    //签名步骤四：所有字符转为大写
    $string = strtoupper($string);

    return $string;
}
